import wepy from 'wepy'
import tip from './tip'
const wxRequest = async (params = {}, url) => {
  tip.loading()
  let data = params.query || {}
  let header = params.header || { 'Content-Type': 'application/x-www-form-urlencoded' }
  let tempFilePaths = params.tempFilePaths
  let fileName = params.fileName || 'file'
  let res = {}
  if (!tempFilePaths) {
    res = await wepy.request({
      url: url,
      method: params.method || 'GET',
      data: data,
      header: header
    })
  } else {
    res = await wepy.uploadFile({
      header: header,
      url: url,
      filePath: tempFilePaths[0],
      name: fileName,
      formData: data
    })
  }
  tip.loaded()
  return res
}
module.exports = {
  wxRequest
}
